<template>
  <div class="addform">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="学校名称:" prop="eeSname">
        <el-input v-model="ruleForm.eeSname"></el-input>
      </el-form-item>
      <el-form-item label="教育时代:" prop="eeEra">
        <el-select v-model="ruleForm.eeEra" placeholder="请选择">
          <el-option
            v-for="item in ruleForm.eeEraList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="自我评价:" prop="eeSeva">
        <el-input v-model="ruleForm.eeSeva"></el-input>
      </el-form-item>
      <el-form-item label="起止时间:" prop="eeStart">
        <el-date-picker
          v-model="ruleForm.eeStart"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
        <i class="el-icon-minus"></i>
        <el-date-picker
          v-model="ruleForm.eeEnd"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="概况讲解:" prop="eeOve">
        <el-input
          type="textarea"
          v-model="ruleForm.eeOve"
          :rows="4"
          class="inputL"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">
          修改学历
        </el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      successVisible: false,
      dialogImageUrl: "",
      dialogVisible: false,
      ruleForm: {
        //必须保证前后端pojo类名字一样
        eeEraList: [
          {
            value: "小学",
            label: "小学",
          },
          {
            value: "初中",
            label: "初中",
          },
          {
            value: "高中",
            label: "高中",
          },
          {
            value: "学士",
            label: "大学",
          },
          {
            value: "硕士",
            label: "研究生",
          },
        ]
      },
      rules: {
        //如果没输入的提示信息
        eeEra: [{ required: true, message: "请选择教育时期", trigger: "blur" }],
        eeSname: [
          { required: true, message: "请输入学校名称", trigger: "blur" },
          { max: 50, message: "最大长度50个字", trigger: "blur" },
        ],
        eeSeva: [
          { required: true, message: "请输入自我评价", trigger: "blur" },
          { max: 50, message: "最大长度50个字", trigger: "blur" },
        ],
        eeStart: [
          { required: true, message: "请输入作者名言", trigger: "blur" },
        ],
        eeEnd: [{ required: true, message: "请输入作者名言", trigger: "blur" }],
      },
    };
  },
  methods: {
    assignData(id) {
      console.log("父亲传过来" + id);
      const _this = this;
      //打开页面向后端请求显示全部数据
      this.axios({
        method: "get",
        // 公共变量baseUrl() 已经定义在main.js.用于修改后端端口
        url: _this.baseUrl + "/index3/get/eduExpOne/" + id,
      }).then(function (resp) {
        console.log("获取数据成功");
        _this.ruleForm = resp.data;
      });
    },
    submitForm(formName) {
      // 提交方法 先判断提交表单是否有空=>validate
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log("进入修改");
          // 由于axios内部必须使用_this才能使用this
          const _this = this;
          this.axios({
            method: "post",
            url: _this.baseUrl + "/index/post/editEduExp",
            //传递给后端的数据
            data: _this.ruleForm
          }).then(function (resp) {
            console.log(resp.data);
            _this.$parent.$parent.successEdit();
          });
        } else {
          console.log("修改失败");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="less" scoped>
.addform {
  width: 100%;
  margin: 0 auto;
  .xx {
    float: left;
  }
}
</style>